package leetcode;

import java.util.*;

public class LeetcodeMain86 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> list=new ArrayList<>();
        if (p.length()>s.length()){
            return list;
        }
        char[] ch=p.toCharArray();
        Arrays.sort(ch);
        int length=s.length();
        int pLength=p.length();
        String str=String.valueOf(ch);
        for (int i = 0; i < length; i++) {
            if (i+pLength<=length){
                String s1=s.substring(i,i+pLength);
                char[] arr=s1.toCharArray();
                Arrays.sort(arr);
                s1=String.valueOf(arr);
                if (s1.equals(str)){
                    list.add(i);
                }
            }
        }
        return list;
    }
    public static void main2(String[] args) {
        Scanner in=new Scanner(System.in);
        while (in.hasNext()){
            int n=in.nextInt();
            int m=in.nextInt();
            List<List<Integer>> res=new ArrayList<>();
            List<Integer> pro=new ArrayList<>();
            Back(n,0,m,1,pro,res);
            for (List<Integer> list:res) {
                int size=list.size();
                System.out.printf("%d",list.get(0));
                for (int i = 1; i < size; i++) {
                    System.out.printf(" %d",list.get(i));
                }
                System.out.println();
            }
        }
    }
    public static void Back(int n,int sum,int k,int starIndex,List<Integer> pro,List<List<Integer>> res){
        if (sum==k){
            res.add(new ArrayList<>(pro));
            return;
        }
        for (int i = starIndex; i <= n&&sum+i<=k; i++) {
            sum+=i;
            pro.add(i);
            Back(n, sum, k, i+1, pro, res);
            pro.remove(pro.size()-1);
            sum-=i;
        }
    }



    public static String[] arr={"","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while (in.hasNext()){
            int num=in.nextInt();
            Set<String> set=new HashSet<>();
            in.nextLine();
            for (int i = 0; i < num; i++) {
                String str=in.nextLine();
                GetTel(str,set);
            }
            PriorityQueue<String> queue=new PriorityQueue<>((o1, o2) -> o1.compareTo(o2));
            for (String s:set) {
                queue.offer(s);
            }
            while (!queue.isEmpty()){
                System.out.println(queue.poll());
            }
            System.out.println();
        }
    }
    public static void GetTel(String str,Set<String> set) {
        StringBuffer buffer = new StringBuffer();
        int length = str.length();
        int count=0;
        for (int i = 0; i < length; i++) {
            char ch=str.charAt(i);
            if (Character.isDigit(ch)){
                buffer.append(ch);
            }else if (ch=='-'){
                continue;
            }else {
                String str1="";
                str1+=ch;
                for (int j = 2; j <= 9; j++) {
                    if (arr[j].contains(str1)){
                        buffer.append(j);
                        break;
                    }
                }
            }
            count++;
            if (count==3){
                buffer.append('-');
            }
        }
            set.add(buffer.toString());
    }
}
